import os
import requests
from pathlib import Path

def download_file(url, save_path):
    """下载文件并保存到指定路径"""
    response = requests.get(url)
    if response.status_code == 200:
        os.makedirs(os.path.dirname(save_path), exist_ok=True)
        with open(save_path, 'wb') as f:
            f.write(response.content)
        print(f"Downloaded: {save_path}")
    else:
        print(f"Failed to download: {url}")

def main():
    # 项目根目录
    BASE_DIR = Path(__file__).resolve().parent
    STATIC_DIR = BASE_DIR / 'static'

    # 需要下载的文件
    files = {
        # Bootstrap CSS
        'css/bootstrap.min.css': 'https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css',
        'css/bootstrap.min.css.map': 'https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css.map',
        
        # Bootstrap JS
        'js/bootstrap.bundle.min.js': 'https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js',
        'js/bootstrap.bundle.min.js.map': 'https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js.map',
        
        # jQuery
        'js/jquery.min.js': 'https://code.jquery.com/jquery-3.6.0.min.js',
    }

    # 下载文件
    for path, url in files.items():
        save_path = STATIC_DIR / path
        download_file(url, save_path)

if __name__ == '__main__':
    main() 